﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;

using OgilvyOne.UKNow.Mobile.Model.Events;
using ECCIT.Extension.Weibo_v2.Common;
using OgilvyOne.UKNow.Mobile.Utilities;
using OgilvyOne.UKNow.DALFactory;
using OgilvyOne.UKNow.IDAL;
using OgilvyOne.UKNow.Model;


namespace OgilvyOne.UKNow.Mobile.APIs.Comments
{
    using EventCommentModel = OgilvyOne.UKNow.Model.EventComment;

    public class EventCommentInfo : IHttpHandler
    {
        public bool IsReusable { get { return true; } }

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string currindex = context.Request.Params["current_page"];
                string pagesize = context.Request.Params["page_size"];

                string uid = context.Request.Params["uid"];
                string langid = context.Request.Params["langid"];

                getALLMod(int.Parse(pagesize), int.Parse(currindex), context, int.Parse(uid),int.Parse(langid));
            }
            catch (Exception)
            {

                context.Response.Write(ResultUtility.ReturnResultJson("-500", "", "获取列表失败"));
            }
                                     
        }
        private void getALLMod(int pagesize, int currindex, HttpContext htc, int? uid, int? langid)
        {
            IDALEventsComment use;
            List<EventComment> list;
            if (langid != null)
            {
                int a = Convert.ToInt32(langid);
                 use = EventsCommentDALFactory.Create(a);
                 list = use.getModel(a,uid,currindex,pagesize);
            }
            else
            {
                 use = EventsCommentDALFactory.Create(1033);//不将1033传到getModel方法中
                 list = use.getModel(null,uid,currindex,pagesize);
            }


            if (list != null)
            {
                EventCommentList ullist = new EventCommentList();
                ullist.List = list;
                ullist.CurrentPageIndex = currindex;
                ullist.PageCount = list.Capacity % pagesize == 0 ? list.Capacity / pagesize : list.Capacity / pagesize + 1;
                ullist.TotalCount = list.Capacity;
                string s = JsonSerializationHelper.ObjectToJson(ullist);
                htc.Response.Write(ResultUtility.ReturnResultJson("0", s, "获取列表成功"));

            }
        }
    }
}
